from src import log


class Question:

    desc:str;
    knowledge:str;


class Parser:

    def __init__(self):
        import json
        from docx import Document
        from docx.shared import Pt
        from docx.enum.text import WD_ALIGN_PARAGRAPH

        # 假设你已经有了 JSON 数据字符串
        json_data = '''{
          "RequestId": "7C4F92D0-62AA-5413-8E0A-AD0153102BB7",
          "Data": {
            "algo_version": "74c620929184b391f1f3647b6a4704381c84fe9e",
            "angle": 0,
            "content": "10.如图， 在矩形ABCD中， E为AB的中点， P为 BC 边上的任意一点，把 △P BE 沿PE折叠，得到 △PFE， 连接CF.若 AB=10，BC=12， 则CF的最小值为. A. D F E B C P ...",
            "figure": [
              {
                "box": {"angle": -90, "h": 0, "w": 0, "x": 0, "y": 0},
                "h": 111,
                "points": [
                  {"x": 56, "y": 328},
                  {"x": 300, "y": 328},
                  {"x": 300, "y": 439},
                  {"x": 56, "y": 439}
                ],
                "type": "subject_pattern",
                "w": 244,
                "x": 56,
                "y": 328
              },
              ...
            ],
            "height": 457,
            "orgHeight": 457,
            "orgWidth": 719,
            "prism_version": "1.0.9",
            "prism_wnum": 36,
            "prism_wordsInfo": [
              {
                "angle": 0,
                "charInfo": [
                  {"h": 14, "prob": 99, "w": 5, "word": "1", "x": 54, "y": 26},
                  {"h": 14, "prob": 99, "w": 7, "word": "0", "x": 59, "y": 26},
                  ...
                ],
                "direction": 0,
                "height": 12,
                "pos": [
                  {"x": 50, "y": 26},
                  {"x": 362, "y": 26},
                  {"x": 362, "y": 39},
                  {"x": 50, "y": 39}
                ],
                "prob": 99,
                "recClassify": 0,
                "width": 312,
                "word": "10.如图， 在矩形ABCD中， E为AB的中点， P为",
                "x": 50,
                "y": 26
              },
              ...
            ]
          }
        }'''

        # 解析 JSON 数据
        data = json.loads(json_data)
        content = data["Data"]["content"]
        figures = data["Data"]["figure"]

        # 创建一个新的 Word 文档
        doc = Document()

        # 添加题目内容
        paragraph = doc.add_paragraph(content)
        paragraph.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
        font = paragraph.style.font
        font.name = 'Arial'
        font.size = Pt(12)

        # 添加图形描述
        for figure in figures:
            points = figure["points"]
            box = figure["box"]
            figure_type = figure["type"]
            # 这里可以进一步处理图形数据，例如生成图形描述或插入图片
            doc.add_paragraph(f"Figure Type: {figure_type}, Points: {points}, Box: {box}")

        # 保存文档
        doc.save('output.docx')
        log.debug("Document saved successfully.")